package com.kingyun.gpsinspection.purificationservice.services.jsm.innerservice.impl.device;

import com.cqhilink.api.common.utils.UniqueUtil;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.jsm.DeviceMaintenanceMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.Device;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.DeviceMaintenance;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.EmployeeVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.device.JsmDeviceMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by huangxueqian on 2017/5/5/005.
 */
public class JsmDeviceMaintenanceServiceImpl implements JsmDeviceMaintenanceService {
    @Autowired
    private DeviceMaintenanceMapper deviceMaintenanceMapper;

    @Override
    public int insertDeviceMaintenance(Device device, DeviceMaintenance deviceMaintenance, EmployeeVo employee) throws Exception {
        int resInt = 0;
        if (deviceMaintenance.getMaintenanceId() == null) {
            deviceMaintenance.setMaintenanceId(UniqueUtil.uuid());
            deviceMaintenance.setStatus("0");
            deviceMaintenance.setDeviceId(device.getDeviceId());
            resInt = resInt + deviceMaintenanceMapper.insertSelective(deviceMaintenance);
        } else {
            resInt = deviceMaintenanceMapper.updateByPrimaryKeySelective(deviceMaintenance);
        }

        return resInt;
    }

    @Override
    public int insertDeviceMaintenances(Device device,List<DeviceMaintenance> deviceMaintenances, EmployeeVo employee) throws Exception {
        int resInt = 0;
        if (deviceMaintenances != null && deviceMaintenances.size() > 0) {
            for (DeviceMaintenance deviceMaintenance : deviceMaintenances) {
                resInt = resInt + insertDeviceMaintenance(device,deviceMaintenance, employee);
            }
        }
        return resInt;
    }

    @Override
    public List<DeviceMaintenance> getDeviceMaintenanceList(DeviceMaintenance deviceMaintenance) throws Exception {
        return deviceMaintenanceMapper.selectByDeviceMaintenanceList(deviceMaintenance);
    }

    @Override
    public int delDeviceMaintenances(List<DeviceMaintenance> deviceMaintenances, EmployeeVo employeeVo) {
        int resInt = 0 ;
        if(deviceMaintenances != null && deviceMaintenances.size() > 0){
                    for(DeviceMaintenance deviceMaintenance:deviceMaintenances){
                        resInt = resInt + deviceMaintenanceMapper.deleteByPrimaryKey(deviceMaintenance.getMaintenanceId());
                    }
        }
        return resInt;
    }

    @Override
    public int delDeviceMaintenances(Device device) {
        return deviceMaintenanceMapper.delDeviceMaintenances(device);
    }

    @Override
    public List<DeviceMaintenance> selectByDeviceMaintenanceList(DeviceMaintenance deviceMaintenance) throws Exception {
        return deviceMaintenanceMapper.getDeviceMaintenanceList(deviceMaintenance);
    }

}
